package com.aaa.tmr.controller;

import com.aaa.tmr.entity.Visit;
import com.aaa.tmr.service.VisitService;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;
import com.aaa.tmr.util.Result;
import com.aaa.tmr.util.ReturnStatus;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

/**
 * (Visit)表控制层
 *
 * @author makejava
 * @since 2021-03-23 15:14:20
 */
@Controller
@RequestMapping("visit")
public class VisitController {
    /**
     * 服务对象
     */
    @Resource
    private VisitService visitService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    public Visit selectOne(Integer id) {
        return this.visitService.queryById(id);
    }

    /**
     * 跳转字典类型分页列表页面
     *
     * @return 列表页面
     */
    @RequestMapping("toVisit")
    public String toVisit() {
        return "back/visit-page";
    }

    /**
     * 分页查询方法
     *
     * @param page
     * @param limit
     * @param visit
     * @return
     */
    @ResponseBody
    @RequestMapping("queryAll")
    public Result<java.util.List> queryAll(Integer page, Integer limit, Visit visit) {
        PageInfo pageInfo = visitService.queryAll(page, limit, visit);
        return new Result<>(ReturnStatus.SUCCESS.getCode(), ReturnStatus.SUCCESS.getMessage(),
                pageInfo.getTotal(), pageInfo.getList());
    }

    /**
     * 新增数据
     *
     * @param visit 实例对象
     * @return 实例对象
     */
    @RequestMapping("insert")
    @ResponseBody
    public Result<Visit> insert(Visit visit) {
        return new Result<>(ReturnStatus.SUCCESS.getCode(),
                ReturnStatus.SUCCESS.getMessage(), 0L,
                this.visitService.insert(visit));
    }

    /**
     * 修改数据
     *
     * @param visit 实例对象
     * @return 实例对象
     */
    @PutMapping("update")
    @ResponseBody
    public Result<Visit> update(Visit visit) {
        return new Result<>(ReturnStatus.SUCCESS.getCode(),
                ReturnStatus.SUCCESS.getMessage(), 0L,
                this.visitService.update(visit));
    }

    /**
     * 通过主键删除数据
     *
     * @param visitId 主键
     * @return 是否成功
     */
    @DeleteMapping("deleteById")
    @ResponseBody
    public Result<Boolean> deleteById(Integer visitId) {
        return new Result<>(ReturnStatus.SUCCESS.getCode(),
                ReturnStatus.SUCCESS.getMessage(), 0L,
                this.visitService.deleteById(visitId));
    }

    /**
     * 通过主键删除数据
     *
     * @param visitIds 主键
     * @return 是否成功
     */
    @DeleteMapping("deleteByIds")
    @ResponseBody
    public Result<Boolean> deleteByIds(Integer visitIds) {
        return new Result<>(ReturnStatus.SUCCESS.getCode(),
                ReturnStatus.SUCCESS.getMessage(), 0L,
                this.visitService.deleteById(visitIds));
    }

    /**
     * 导入excel
     *
     * @return 对象列表
     */
    @ResponseBody
    @RequestMapping("importVisit")
    public Result<Boolean> importVisit(@RequestParam MultipartFile file) {
        return new Result<>(ReturnStatus.SUCCESS.getCode(),
                ReturnStatus.SUCCESS.getMessage(),
                0L,visitService.importVisit(file));
    }

    /**
     * 导出excel
     *
     * @return 对象列表
     */
    @ResponseBody
    @RequestMapping("exportVisit")
    public Result<Boolean> exportVisit(Visit visit) {
        return new Result<>(ReturnStatus.SUCCESS.getCode(),
                ReturnStatus.SUCCESS.getMessage(),
                0L,visitService.exportVisit(visit));
    }

}
